package kr.ac.mju.mdc.mjuapp.information;

import java.util.ArrayList;

import kr.ac.mju.mdc.mjuapp.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ReleaseNoteListViewActivity extends Activity {
	
	ArrayList<ReleaseNote> releaseNoteList;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    // TODO Auto-generated method stub
	    setContentView(R.layout.information_releasenote_list_layout);
	    releaseNoteList = new ArrayList<ReleaseNote>();
	    
	    String[] titles = this.getResources().getStringArray(R.array.releaseNote_title);
	    String[] items = this.getResources().getStringArray(R.array.releaseNote_items);
	    ReleaseNote releaseNote;
	    
	    for (int i = 0; i < titles.length; i++) {
	    	releaseNote = new ReleaseNote();
	    	releaseNote.setDate(titles[i].toString());
	    	releaseNote.setItem(items[i].toString());
	    	releaseNoteList.add(releaseNote);
	    }
	    
	    ReleaseNoteAdapter rAdapter = new ReleaseNoteAdapter(this, R.layout.information_releasenote_list_row_layout, releaseNoteList);
	    ListView lv = (ListView)findViewById(R.id.release_listview);
	    lv.setAdapter(rAdapter);
	}
}

class ReleaseNote {
	private String date;
	private String items;

	public void setDate(String date) {
		this.date = date;
	}
	public String getDate() {
		return date;
	}
	
	public void setItem(String item) {
		this.items = item;
	}
	
	public String getItem() {
		return items;
	}
}

//어댑터 클래스
class ReleaseNoteAdapter extends BaseAdapter {
	Context context;
	LayoutInflater Inflater;
	ArrayList<ReleaseNote> releaseNoteList;
	int layout;

	public ReleaseNoteAdapter(Context context, int layout, ArrayList<ReleaseNote> list) {
		this.context = context;
		Inflater = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
		releaseNoteList = list;
		this.layout = layout;
	}

	public int getCount() {
		return releaseNoteList.size();
	}

	public String getItem(int position) {
		return releaseNoteList.get(position).getDate();
	}

	public long getItemId(int position) {
		return position;
	}

	// 각 항목의 뷰 생성
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = Inflater.inflate(layout, parent, false);
		}
		
		TextView date = (TextView)convertView.findViewById(R.id.release_list_row_date);
		date.setText(releaseNoteList.get(position).getDate());
		
		TextView item = (TextView)convertView.findViewById(R.id.release_list_row_item);
		item.setText(releaseNoteList.get(position).getItem());

		return convertView;
	}
}
/* end of file */